{% extends "base.html" %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2"><i class="fas fa-search me-2"></i>职位信息检索</h1>
</div>

<div class="card mb-4">
    <div class="card-header">
        <h5 class="card-title mb-0"><i class="fas fa-filter me-2"></i>搜索条件</h5>
    </div>
    <div class="card-body">
        <form method="GET" class="row g-3">
            <div class="col-md-4">
                <label for="city" class="form-label">城市</label>
                <input type="text" class="form-control" id="city" name="city" value="{{ city }}" placeholder="输入城市">
            </div>
            <div class="col-md-4">
                <label for="industry" class="form-label">行业</label>
                <input type="text" class="form-control" id="industry" name="industry" value="{{ industry }}" placeholder="输入行业">
            </div>
            <div class="col-md-4">
                <label for="salary_range" class="form-label">薪资范围</label>
                <select class="form-select" id="salary_range" name="salary_range">
                    <option value="全部" {% if salary_range == '全部' %}selected{% endif %}>全部</option>
                    <option value="10k以下" {% if salary_range == '10k以下' %}selected{% endif %}>10k以下</option>
                    <option value="10-20k" {% if salary_range == '10-20k' %}selected{% endif %}>10-20k</option>
                    <option value="20-30k" {% if salary_range == '20-30k' %}selected{% endif %}>20-30k</option>
                    <option value="30k以上" {% if salary_range == '30k以上' %}selected{% endif %}>30k以上</option>
                </select>
            </div>
            <div class="col-12">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-search me-1"></i>搜索
                </button>
                <a href="{{ url_for('page1') }}" class="btn btn-secondary">
                    <i class="fas fa-redo me-1"></i>重置
                </a>
            </div>
        </form>
    </div>
</div>

<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="card-title mb-0"><i class="fas fa-list me-2"></i>职位列表</h5>
        <span class="badge bg-primary">共 {{ total_positions }} 个职位</span>
    </div>
    <div class="card-body">
        {% if positions %}
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead class="table-dark">
                    <tr>
                        <th>职位名称</th>
                        <th>薪资</th>
                        <th>工作经验</th>
                        <th>学历要求</th>
                        <th>城市</th>
                        <th>区域</th>
                        <th>公司名称</th>
                        <th>行业</th>
                        <th>公司规模</th>
                        <th>技能要求</th>
                    </tr>
                </thead>
                <tbody>
                    {% for position in positions %}
                    <tr>
                        <td><strong>{{ position.position }}</strong></td>
                        <td><span class="badge bg-success">{{ position.salary }}</span></td>
                        <td>{{ position.experience }}</td>
                        <td>
                            {% if position.education == '本科' %}
                                <span class="badge bg-info">{{ position.education }}</span>
                            {% elif position.education == '硕士' %}
                                <span class="badge bg-warning">{{ position.education }}</span>
                            {% elif position.education == '博士' %}
                                <span class="badge bg-danger">{{ position.education }}</span>
                            {% else %}
                                <span class="badge bg-secondary">{{ position.education }}</span>
                            {% endif %}
                        </td>
                        <td>{{ position.city }}</td>
                        <td>{{ position.district }}</td>
                        <td>{{ position.company }}</td>
                        <td>{{ position.industry }}</td>
                        <td>{{ position.company_size }}</td>
                        <td>
                            <small class="text-muted">{{ position.skills }}</small>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <!-- 分页导航 -->
        {% if total_pages > 1 %}
        <nav aria-label="Page navigation">
            <ul class="pagination justify-content-center">
                <!-- 上一页 -->
                <li class="page-item {% if page == 1 %}disabled{% endif %}">
                    <a class="page-link" href="{% if page > 1 %}{{ url_for('page1', page=page-1, city=city, industry=industry, salary_range=salary_range) }}{% else %}#{% endif %}">
                        <i class="fas fa-chevron-left"></i> 上一页
                    </a>
                </li>

                <!-- 页码 -->
                {% for p in range(1, total_pages + 1) %}
                    {% if p == page %}
                        <li class="page-item active">
                            <span class="page-link">{{ p }}</span>
                        </li>
                    {% elif p >= page - 2 and p <= page + 2 %}
                        <li class="page-item">
                            <a class="page-link" href="{{ url_for('page1', page=p, city=city, industry=industry, salary_range=salary_range) }}">{{ p }}</a>
                        </li>
                    {% elif p == 1 or p == total_pages %}
                        <li class="page-item">
                            <a class="page-link" href="{{ url_for('page1', page=p, city=city, industry=industry, salary_range=salary_range) }}">{{ p }}</a>
                        </li>
                    {% elif p == page - 3 or p == page + 3 %}
                        <li class="page-item disabled">
                            <span class="page-link">...</span>
                        </li>
                    {% endif %}
                {% endfor %}

                <!-- 下一页 -->
                <li class="page-item {% if page == total_pages %}disabled{% endif %}">
                    <a class="page-link" href="{% if page < total_pages %}{{ url_for('page1', page=page+1, city=city, industry=industry, salary_range=salary_range) }}{% else %}#{% endif %}">
                        下一页 <i class="fas fa-chevron-right"></i>
                    </a>
                </li>
            </ul>
        </nav>

        <div class="text-center text-muted mt-2">
            共 {{ total_positions }} 条记录
        </div>
        {% endif %}

        {% else %}
        <div class="text-center py-5">
            <i class="fas fa-search fa-3x text-muted mb-3"></i>
            <h4 class="text-muted">未找到符合条件的职位</h4>
            <p class="text-muted">请尝试调整搜索条件</p>
            <a href="{{ url_for('page1') }}" class="btn btn-primary mt-3">
                <i class="fas fa-redo me-1"></i>重新搜索
            </a>
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}